package ssi.peeno.messages.lowlevel;

import java.security.PrivateKey;
import java.security.PublicKey;

import org.bouncycastle.util.encoders.Base64;

import ssi.peeno.ciphers.SHA1Digester;
import ssi.peeno.ciphers.SymCipher;

public class RegMessage extends LowLevelMessage {
	private String username;
	private String email;
	private String password;
	private PublicKey pubKey;
	private PrivateKey privKey;
	private String cryptedPriv;
	private long timestamp;
	
	public String getUsername() {
		return username;
	}
	
	public void setUsername(String username) {
		this.username = username;
	}
	
	public String getEmail() {
		return email;
	}
	
	public void setEmail(String email) {
		this.email = email;
	}
	
	public String getPassword() {
		return password;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	
	public PublicKey getPubKey() {
		return pubKey;
	}
	
	public void setPubKey(PublicKey pubKey) {
		this.pubKey = pubKey;
	}

	public PrivateKey getPrivKey() {
		return privKey;
	}

	public void setPrivKey(PrivateKey privKey) {
		this.privKey = privKey;
	}

	public String getCryptedPriv() {
		return cryptedPriv;
	}

	public void setCryptedPriv(String cryptedPriv) {
		this.cryptedPriv = cryptedPriv;
	}

	public long getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(long l) {
		this.timestamp = l;
	}

	public String toString(){
		SymCipher sym = new SymCipher();
		sym.setKey(password);
		String chiave = new String((Base64.encode(pubKey.getEncoded())));
		String priv = "";
		try {
			priv = sym.crypt(new String(Base64.encode(privKey.getEncoded())));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return username + "!-!" + email + "!-!" + SHA1Digester.digestString(password) + "!-!" + timestamp + "\r\n" + chiave.length() + "\r\n" + chiave + "\r\n" + priv;
	}
}
